<?php

  require_once "JooS/Stream/Entity/Abstract.php";

 /**
  * @package JooS
  * @subpackage PHPackager
  */

  abstract class JooS_PHPackager_FS_Entity extends JooS_Stream_Entity_Abstract {
    /**
     * @var bool
     */
    private $_virtual;

    /**
     * @param string $path
     * @param string $type
     * @return JooS_PHPackager_FS_Entity
     */
    final public static function getInstance($path, $type = null) {
      /* @var $entity JooS_PHPackager_FS_Entity */
      $entity = null;
      
      if ($type !== null) {
        require_once "JooS/Loader.php";
        
        $className = __CLASS__ . "_" . $type;
        if (JooS_Loader::loadClass($className)) {
          $entity = new $className($path);
        }
      }
      elseif (!file_exists($path)) {
        require_once "JooS/PHPackager/FS/Entity/None.php";
        
        $entity = new JooS_PHPackager_FS_Entity_None($path);
      }
      elseif (is_file($path)) {
        require_once "JooS/PHPackager/FS/Entity/File.php";

        $entity = new JooS_PHPackager_FS_Entity_File($path);
      }
      elseif (is_dir($path)) {
        require_once "JooS/PHPackager/FS/Entity/Dir.php";

        $entity = new JooS_PHPackager_FS_Entity_Dir($path);
      }
      if (is_null($entity)) {
        require_once "JooS/PHPackager/FS/Entity/Unknown.php";
        
        $entity = new JooS_PHPackager_FS_Entity_Unknown($path);
      }
      if ($type !== null) {
        $entity->_setVirtual(true);
      }

      return $entity;
    }
    
    /**
     * @param string $path
     */
    protected function __construct($path) {
      parent::__construct($path);
      
      $this->_setVirtual(false);
    }

    /**
     * @return bool
     */
    public function is_virtual() {
      return $this->_virtual;
    }

    /**
     * @param bool $virtual 
     */
    protected function _setVirtual($virtual) {
      $this->_virtual = !!$virtual;
    }
  }
